import 'package:aio/aio.dart';
import 'package:flutter/material.dart';
import 'package:app/src/presenter/review_presenter.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_node_list.dart';
import 'package:app/src/ui/route/works/public/review_details_ui.dart';
import 'package:app/src/ui/route/works/public/review_submitted.dart';

import '../../../../http/bean/ywx_limit.dart';
import '../../../../manager/audit_manager.dart';
import '../../worksdo/type16_material_requisition/public/items/ui_attachment.dart';
import 'acom/ui_purorder_audit_form.dart';
import 'item/ui_purorder_audit.dart';

///采购单审核详情
class PurOrderAuditDetailsRoute extends StatefulWidget {
  YwxItem item;

  PurOrderAuditDetailsRoute(this.item);

  @override
  _State createState() => _State();
}

class _State extends State<PurOrderAuditDetailsRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    presenter.getContractapplygetinfoWithDelay(context); //获取审核详情数据
  }

  @override
  Widget build(BuildContext context) {
    return ReviewDetailsUi.build(context, presenter, _body);
  }

  Widget _body(BuildContext context) {
    if (presenter?.mDatas == null) {
      return AppUi.getEmptyView();
    }
    var mDatas = presenter?.mDatas?.PurOrderInfo;
    var mOldDatas = presenter?.mOldDatas?.PurOrderInfo;

    ///正常请购单审核
    List<Widget> children = [];
    children.add(
        UiPurorderAudit.build(context, mDatas, mOldDatas, setState)); //采购单信息
    children
        .add(UiPurorderAuditForm.build(context, mDatas, widget.item)); //物料信息
    children.add(
        UiAttachment.build(context, mDatas?.FilePatch, isShowEmpty: true)); //附件
    children.add(UiNoteList.build(context, presenter?.mDatas?.NodeList)); //审核日志
    // YwxId":"N8002-1","YwxName":"采购申请"
    var YwxId = AuditManager.getAuditManager().YwxId;
    var hasBack = true; //退回
    var hasRevocation = false; //撤销
    if (YwxId == "N8002-1") {
      //采购申请
      hasBack = false;
      hasRevocation = true;
    }
    return Column(
      children: [
        Expanded(child: UiBase.listView(context, children)),
        Visibility(
            child: ReviewSubmittedStateful(
              presenter?.mDatas,
              hasBack: hasBack,
              hasRevocation: hasRevocation,
              onlyBack: false,
              hasEnd: false,
              hasAuditOpinion: true,
              callbackWithT: (subData) {
                //fixme 提交参数数据
                // subData.GetCheckPurDemand = mDatas?.PurDemandList;
                // print(
                //     "========================================================入库仓位：${mDatas?.Storehouse}");
                // print(
                //     "========================================================检验员：${mDatas?.Checker}");
                // print(
                //     "========================================================入库仓位：${subData.FLoseApplyInfo?.Storehouse}");
                // print(
                //     "========================================================检验员：${subData.FLoseApplyInfo?.Checker}");
              },
            ),
            visible: presenter?.mDatas != null)
      ],
    );
  }
}

class _Presenter extends ReviewPresenter {}
